
import mjin2

class GameXML(mjin2.XML):
    def __init__(self, pathResolver):
        super(GameXML, self).__init__()
        self.pathResolver = pathResolver
    def loadAndDereference(self, fileName):
        r = self.load(fileName)
        if (len(r.nodes)):
            root = r.nodes[0]
            proceed = True
            while (proceed):
                proceed = False
                nodesNb = len(root.nodes)
                for i in range(nodesNb):
                    # Node to dereference.
                    if (root.nodes[i].name == root.name):
                        proceed = True
                        subFileName = self.pathResolver.findFile(
                            root.nodes[i].nodes[0].value)
                        sub = self.load(subFileName)
                        root.nodes[i:i + 1] = sub.nodes[0].nodes
        return r
